public class Solution43 {
    public String multiply(String num1, String num2) {
        char[] c1=num1.toCharArray();
        char[] c2=num2.toCharArray();
        int[] i1=new int[c1.length];
        int[] i2=new int[c2.length];
        for (int i=0;i<c1.length;i++){
            i1[i]=c1[c1.length-i-1]-'0';
        }
        for (int i=0;i<c2.length;i++){
            i2[i]=c2[c2.length-i-1]-'0';
        }
        int[] i3=new int[c1.length+c2.length];
        for (int i=0;i<i1.length;i++){
            for (int j=0;j<i2.length;j++){
                i3[i+j]+=i1[i]*i2[j];
                int t=i+j;
                while (i3[t]>=10){
                    i3[t+1]+=i3[t]/10;
                    i3[t]%=10;
                    t++;
                }
            }
        }
        int start;
        if (i3[i3.length-1]!=0){
            start=i3.length-1;
        }else{
            start=i3.length-2;
        }
        StringBuilder stringBuilder=new StringBuilder();
        for (int i=start;i>=0;i--){
            stringBuilder.append(i3[i]);
        }
        while (stringBuilder.length()>1 && stringBuilder.charAt(0)=='0'){
            stringBuilder.deleteCharAt(0);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution43().multiply("123","456"));
    }
}
